home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / toku3 / httrack-3.32-2.exe / {app} / src_win / WinHTTrack / MainFrm.cpp < prev    next >
C/C++ Source or Header  |  2002-04-13  |  4KB  |  155 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6. #include "mainfrm.h"
  7. #include "resource.h"
  8. #include "Shell.h"
  9.  
  10.  
  11. IMPLEMENT_DYNCREATE(CMainFrame, CMDIFrameWnd)
  12. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  13.     //{{AFX_MSG_MAP(CMainFrame)
  14.     ON_WM_CREATE()
  15.     ON_WM_CLOSE()
  16.     //}}AFX_MSG_MAP
  17. END_MESSAGE_MAP()
  18.  
  19. static UINT BASED_CODE buttons[] =
  20. {
  21.     // same order as in the bitmap 'toolbar.bmp'
  22.     ID_FILE_NEW, ID_FILE_OPEN, ID_FILE_SAVE, 0,
  23.     ID_EDIT_CUT, ID_EDIT_COPY, ID_EDIT_PASTE, 0,
  24.     ID_FILE_PRINT, ID_APP_ABOUT,
  25. };
  26.  
  27. static UINT BASED_CODE indicators[] =
  28. {
  29.     0, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
  30. };
  31.  
  32. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  33. {
  34.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  35.         return -1;
  36.  
  37. /*
  38.     if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  39.         | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  40.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  41.     {
  42.         TRACE0("Failed to create toolbar\n");
  43.         return -1;      // fail to create
  44.     }
  45. */
  46.  
  47.     if (!m_wndStatusBar.Create(this) ||
  48.         !m_wndStatusBar.SetIndicators(indicators,
  49.           sizeof(indicators)/sizeof(UINT)))
  50.     {
  51.         TRACE0("Failed to create status bar\n");
  52.         return -1;      // fail to create
  53.     }
  54.  
  55.     // TODO: Delete these three lines if you don't want the toolbar to
  56.     //  be dockable
  57.     /*
  58.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  59.   EnableDocking(CBRS_ALIGN_ANY);
  60.     DockControlBar(&m_wndToolBar);
  61. */
  62.  
  63.   return 0;
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Helpers for saving/restoring window state
  68.  
  69. static TCHAR BASED_CODE szSection[] = _T("Settings");
  70. static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
  71. static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  72.  
  73. static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp)
  74. {
  75.     CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
  76.     if (strBuffer.IsEmpty())
  77.         return FALSE;
  78.  
  79.     WINDOWPLACEMENT wp;
  80.     int nRead = _stscanf(strBuffer, szFormat,
  81.         &wp.flags, &wp.showCmd,
  82.         &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  83.         &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  84.         &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  85.         &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  86.  
  87.     if (nRead != 10)
  88.         return FALSE;
  89.  
  90.     wp.length = sizeof wp;
  91.     *pwp = wp;
  92.     return TRUE;
  93. }
  94.  
  95. static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp)
  96.     // write a window placement to settings section of app's ini file
  97. {
  98.     TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  99.  
  100.     wsprintf(szBuffer, szFormat,
  101.         pwp->flags, pwp->showCmd,
  102.         pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  103.         pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  104.         pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  105.         pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  106.     AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
  107. }
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110.  
  111. void CMainFrame::InitialShowWindow(UINT nCmdShow)
  112. {
  113.     WINDOWPLACEMENT wp;
  114.     if (!ReadWindowPlacement(&wp))
  115.     {
  116.         ShowWindow(SW_SHOWMAXIMIZED);   /* by default, maximized */
  117.         //ShowWindow(nCmdShow);
  118.         return;
  119.     }
  120.     if (nCmdShow != SW_SHOWNORMAL)
  121.         wp.showCmd = nCmdShow;
  122.     SetWindowPlacement(&wp);
  123.     ShowWindow(wp.showCmd);
  124. }
  125.  
  126. void CMainFrame::OnClose()
  127. {
  128.     // before it is destroyed, save the position of the window
  129.     WINDOWPLACEMENT wp;
  130.     wp.length = sizeof wp;
  131.     if (GetWindowPlacement(&wp))
  132.     {
  133.         wp.flags = 0;
  134.         if (IsZoomed())
  135.             wp.flags |= WPF_RESTORETOMAXIMIZED;
  136.         // and write it to the .INI file
  137.         WriteWindowPlacement(&wp);
  138.     }
  139.  
  140.   /* Ask question (exit) ? */
  141.   if (
  142.     (strcmp(WhttLocation,"FirstInfo") == 0)
  143.     ||
  144.     (strcmp(WhttLocation,"Wid1") == 0)
  145.     ||
  146.     (strcmp(WhttLocation,"Infoend") == 0)
  147.     ) {
  148.     /* Direct */
  149.        CMDIFrameWnd::OnClose();
  150.   } else {
  151.     if (AfxMessageBox(LANG(LANG_J1),MB_OKCANCEL)==IDOK)
  152.         CMDIFrameWnd::OnClose();
  153.   }
  154. }
  155.